package cn.com.huzo.webapp.controller.financial;

import cn.com.huzo.model.entities.financial.ReportPaymentForMaterialEntity;
import cn.com.huzo.model.entities.financial.ReportStyleCostEntity;
import cn.com.huzo.model.entities.inventory.ReportInventoryDetailEntity;
import cn.com.huzo.service.financial.ReportLateArrivalPoManager;
import cn.com.huzo.service.financial.ReportPaymentForMaterialManager;
import cn.com.huzo.service.financial.ReportStyleCostManager;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 财务（二级会计）相关统计、分析、报告
 *
 * @author 吴旭
 */
@Controller
@RequestMapping(value = "/financial/report")
public class FinancialReportController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    @Resource(name = "ReportPaymentForMaterialManager")
    private ReportPaymentForMaterialManager _manager_payment_for_material;

    @Resource(name = "ReportStyleCostManager")
    private ReportStyleCostManager _manager_style_cost;

    @Resource(name = "ReportLateArrivalPoManager")
    private ReportLateArrivalPoManager _manager_late_arrival_po;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 材料购进查询画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/payment_for_material/list.html")
    public ModelAndView redirectPaymentForMaterialWnd(HttpServletRequest request) throws Exception {
        int thisYear = Calendar.getInstance().get(Calendar.YEAR); // 得到今年
        List<Integer> yearList = new ArrayList();
        thisYear = thisYear - 5;
        for (int i = 0; i < 11; i++) {
            yearList.add(thisYear);
            thisYear = thisYear + 1;
        }

        ModelAndView view = new ModelAndView();
        view.addObject("YearList", yearList);
        view.setViewName("financial.report_payment_for_material.list.def");
        return view;
    }

    /**
     * 款成本表画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/style_cost/list.html")
    public ModelAndView redirectStyleCostWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        view.setViewName("financial.report_style_cost.list.def");
        return view;
    }

    /**
     * 晚到订单一览表画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/late_arrival_po/list.html")
    public ModelAndView redirectLateArrivalPoWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        // 为画面设置变量
        int thisYear = Calendar.getInstance().get(Calendar.YEAR); // 得到今年
        List<Integer> yearList = new ArrayList();
        thisYear = thisYear - 5;
        for (int i = 0; i < 11; i++) {
            yearList.add(thisYear);
            thisYear = thisYear + 1;
        }
        view.addObject("YearList", yearList);

        view.setViewName("financial.report_late_arrival_po.list.def");
        return view;
    }

    /**
     * 晚到对账扣款一览表画面
     * <p>
     * @param request
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("/late_arrival_cut_payabled_amount/list.html")
    public ModelAndView redirectLateArrivalCutPayabledAmountWnd(HttpServletRequest request) throws Exception {
        ModelAndView view = new ModelAndView();
        // 为画面设置变量
        int thisYear = Calendar.getInstance().get(Calendar.YEAR); // 得到今年
        List<Integer> yearList = new ArrayList();
        thisYear = thisYear - 5;
        for (int i = 0; i < 11; i++) {
            yearList.add(thisYear);
            thisYear = thisYear + 1;
        }
        view.addObject("YearList", yearList);

        view.setViewName("financial.report_late_arrival_cut_payabled_amount.list.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 根据条件取得材料购进一览表数据。
     *
     * @param criterion 搜索条件
     * @return 该供应商的采购购进情况。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/payment_for_material/fetch.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportPaymentForMaterialEntity> fetchPaymentForMaterial(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_payment_for_material.fetchReportData(criterion);
    }

    /**
     * 根据条件取得该款成本表数据。
     *
     * @param criterion 搜索条件
     * @return 该款的成本明细。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/style_cost/fetch.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportStyleCostEntity> fetchStyleCost(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_style_cost.fetchReportData(criterion);
    }

    /**
     * 根据条件取得晚到订单一览表数据。
     *
     * @param criterion 搜索条件
     * @return 该款的成本明细。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/late_arrival_po/fetch.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<ReportInventoryDetailEntity> fetchLateArrivalPo(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_late_arrival_po.fetchReportData(criterion);
    }

    /**
     * 根据条件取得晚到对账扣款一览表数据。
     *
     * @param criterion 搜索条件
     * @return 该款的成本明细。
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "/late_arrival_cut_payabled_amount/fetch.html",
            method = RequestMethod.POST)
    public @ResponseBody
    List<Map<String, Object>> fetchLateArrivalCutPayabledAmount(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager_late_arrival_po.fetchLateArrivalCutPayabledAmount(criterion);
    }
    // </editor-fold>
}
